package lzyc.pointsManagement.business.notice.controller;

import lzyc.pointsManagement.business.notice.domain.NoticeInfo;
import lzyc.pointsManagement.business.notice.service.NoticeInfoService;
import lzyc.pointsManagement.common.core.controller.BaseController;
import lzyc.pointsManagement.common.core.domain.AjaxResult;
import lzyc.pointsManagement.common.core.page.TableDataInfo;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * (NoticeInfo)表控制层
 *
 * @author yangyang
 * @since 2024-03-10 17:02:25
 */
@RestController
@RequestMapping("/api/v1/notice")
public class NoticeInfoController extends BaseController {
    /**
     * 服务对象
     */
    @Resource
    private NoticeInfoService noticeInfoService;

    /**
     * 新增
     * 
     * @param noticeInfo
     * @return
     */
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult add(@RequestBody NoticeInfo noticeInfo) {
        return toAjax(noticeInfoService.insert(noticeInfo));
    }

    /**
     * 修改
     * 
     * @param noticeInfo
     * @return
     */
    @PostMapping("/update")
    @ResponseBody
    public AjaxResult update(@RequestBody NoticeInfo noticeInfo) {
        return toAjax(noticeInfoService.update(noticeInfo));
    }

    /**
     * 删除
     * 
     * @param ids
     * @return
     */
    @PostMapping("/delete")
    @ResponseBody
    public AjaxResult delete(String ids) {
        return toAjax(noticeInfoService.deleteById(ids));
    }

    /**
     * 分页获取动态列表
     * 
     * @param noticeInfo
     * @return
     */
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(NoticeInfo noticeInfo) {
        startPage();
        List<NoticeInfo> list = noticeInfoService.queryAll(noticeInfo);
        return getDataTable(list);
    }

    /**
     * 当最新动态未读时，获取最新动态列表
     * 
     * @return
     */
    @PostMapping("/unread")
    @ResponseBody
    public AjaxResult unread() {
        return success(noticeInfoService.getUnread());
    }

    /**
     * 通过ID获取公告
     * 
     * @return
     */
    @PostMapping("/detail")
    @ResponseBody
    public AjaxResult detail(String noticeID) {
        return AjaxResult.success(noticeInfoService.queryById(noticeID));
    }

    /**
     * 获取未读用户列表
     * @param projectID  事项ID
     * @return
     */
    @PostMapping("/user/unread")
    @ResponseBody
    public AjaxResult userUnread(String projectID) {
        return AjaxResult.success(noticeInfoService.userUnread(projectID));
    }

    /**
     * 获取已读用户列表
     * @param projectID 事项ID
     * @return
     */
    @PostMapping("/user/read")
    @ResponseBody
    public AjaxResult userRead(String projectID) {
        return AjaxResult.success(noticeInfoService.userRead(projectID));
    }
}